﻿using System;
using StarTrek.Ship;
using StarTrek.UI.Console.MenuItem;
using StarTrek.World;

namespace StarTrek.UI.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            Galaxy theWorld = Galaxy.Instance;
            
            //theWorld.CurrentShip.Travel(theWorld.GetLocation(0,0,0,1,4));
            //theWorld.CurrentShip.Travel(theWorld.GetLocation(0, 0, 0, 2, 3));
            //theWorld.CurrentShip.Travel(theWorld.GetLocation(0, 0, 0, 3, 7));
            //theWorld.CurrentShip.Travel(theWorld.GetLocation(0, 0, 0, 0, 0));
            theWorld.CurrentShip.Travel(theWorld.GetLocation(0, 0, 0, 7, 7));

            //theWorld.CurrentShip.Offense(theWorld.GetVessel("Kong"),
            //    theWorld.CurrentShip.GetWeapon("Phaser"),
            //    100);

            //System.Diagnostics.Debug.WriteLine(String.Join("\r\n", (theWorld.CurrentShip as BaseShip).ShipReport()));

            //theWorld.GetVessel("Kong").Offense(theWorld.CurrentShip, 
            //        theWorld.GetVessel("Kong").GetWeapon("Photon"), 
            //        0);


            
            MenuContext Main = new MenuContext(new MenuDefault());
            Main.Add(new MenuHelp());
            Main.Add(new MenuExit());
            Main.Add(new MenuImpulse());
            Main.Add(new MenuWarp());
            Main.Add(new MenuAttack());
            Main.Add(new MenuRepair());
            Main.Add(new MenuStatus());

            //Begin Main loop.
            while (!Main.TerminateApplicaiton)
            {
                //Draw theWorld.
                DrawWorld.DrawItem(theWorld.CurrentShip.CurrentLocation.Parent,System.Console.Out);

                Main.DisplayMenu(System.Console.Out);
                Main.WaitForInput(System.Console.In);
                if (Main.DispatchAction(System.Console.Out, System.Console.In))
                {
                    //if the player went, then allow the computer to play.
                    if (theWorld.AITurn() && !theWorld.CurrentShip.CreateShipStatus().isDestoryed) 
                        MenuStatus.Draw(Main,System.Console.Out,System.Console.In); //Since the player was just attacked.
                }
                //System.Console.Clear();
            }
        }
    }
}
